package com.example.crm.servlet;

import com.example.crm.dao.ConnectDAO;
import com.example.crm.domain.Connect;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;

@WebServlet("/updateconnect")
public class UpdateConnectServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        // 设置提交过来的编码
        req.setCharacterEncoding("utf-8");


        resp.setContentType("text/html;charset=utf-8");
        PrintWriter pw = resp.getWriter();

        // 1. 接收参数
        Connect c = new Connect();

        c.setId(Integer.parseInt(req.getParameter("id")));
        c.setName(req.getParameter("name"));
        c.setTel(req.getParameter("tel"));

        // 2. 调用DAO
        // 2. 调用DAO
        ConnectDAO dao = new ConnectDAO();
        try {
            int result = dao.update(c);
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }


        // 3. 跳转列表页面
        resp.sendRedirect("listconnect");


    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}